// ===================================================================
// FISIER: Source/source/server/game/char.cpp
// Blocuri OfflineShop: 7
// Fiecare bloc: 'CAUTA' = cateva linii de context existente inainte,
//               'ADAUGA' = codul sistemului (liniile originale din Sinners).
// ===================================================================

// ---------- [1] linii 69-72 (bloc #if) ----------
// CAUTA:
#include "switchbot.h"
#endif
#include "DragonSoul.h"

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
#include "new_offlineshop.h"
#include "new_offlineshop_manager.h"
#endif
// (urmat de:)
//   #include "OXEvent.h"
//   

// ---------- [2] linii 473-480 (bloc #if) ----------
// CAUTA:
	m_iSortInventoryTime = 0;
	memset(&m_iSortSpecialInventoryTime, 0, sizeof(m_iSortSpecialInventoryTime));
#endif

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
	m_pkOfflineShop = NULL;
	m_pkShopSafebox = NULL;
	m_pkAuction = NULL;
	m_pkAuctionGuest = NULL;
	m_pkOfflineShopGuest = NULL;
	m_bIsLookingOfflineshopOfferList = false;
#endif
// (urmat de:)
//   }
//   

// ---------- [3] linii 691-694 (bloc #if) ----------
// CAUTA:
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("´Ů¸Ą °Ĺ·ˇÁß(Ă˘°í,±łČŻ,»óÁˇ)żˇ´Â °łŔÎ»óÁˇŔ» »çżëÇŇ Ľö ľř˝Ŕ´Ď´Ů."));
		return;
	}

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
	if (GetOfflineShopGuest() || GetAuctionGuest())
		return;
#endif
// (urmat de:)
//   
//   	if (GetPart(PART_MAIN) > 2)

// ---------- [4] linii 1462-1477 (bloc #if) ----------
// CAUTA:
	{
		SaveReal();
	}

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
	offlineshop::GetManager().RemoveSafeboxFromCache(GetPlayerID());
	offlineshop::GetManager().RemoveGuestFromShops(this);

	if (m_pkAuctionGuest)
		m_pkAuctionGuest->RemoveGuest(this);

	if (GetOfflineShop())
		SetOfflineShop(nullptr);

	SetShopSafebox(nullptr);

	m_pkAuction = nullptr;
	m_pkAuctionGuest = nullptr;
	m_bIsLookingOfflineshopOfferList = false;
#endif
// (urmat de:)
//   
//   	FlushDelayedSaveItem();

// ---------- [5] linii 6889-6895 (bloc #if) ----------
// CAUTA:

	if (IsLastMoveItemTime())
		return true;

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
	if (iPulse - GetOfflineShopUseTime() < PASSES_PER_SEC(limittime))
		return true;

	if (GetOfflineShopGuest() || GetAuctionGuest())
		return true;
#endif
// (urmat de:)
//   
//   #ifdef ENABLE_SORT_INVENTORY

// ---------- [6] linii 7411-7417 (bloc #if) ----------
// CAUTA:

	if (GetExchange() || GetMyShop() || GetShopOwner() || IsOpenSafebox() || IsCubeOpen())
		return false;

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
	if (iPulse - GetOfflineShopUseTime() < limit_time)
		return false;

	if (GetOfflineShopGuest() || GetAuctionGuest())
		return false;
#endif
// (urmat de:)
//   
//   	if (IsLastMoveItemTime())

// ---------- [7] linii 7863-7918 (bloc #if) ----------
// CAUTA:
		GetDesc()->Packet(&packet, sizeof(TPacketRewardHours));
	}
}

// ADAUGA (dupa liniile de mai sus):
#ifdef __ENABLE_NEW_OFFLINESHOP__
bool CHARACTER::CanTakeInventoryItem(LPITEM item, TItemPos* cell)
{
	int iEmpty = -1;
	if (item->IsDragonSoul())
	{
		cell->window_type = DRAGON_SOUL_INVENTORY;
		cell->cell = iEmpty = GetEmptyDragonSoulInventory(item);
	}
#ifdef ENABLE_SPECIAL_INVENTORY
	else if (item->IsUpgradeItem())
	{
		cell->window_type = UPGRADE_INVENTORY;
		cell->cell = iEmpty = GetEmptyUpgradeInventory(item);

	}
	else if (item->IsPotions())
	{
		cell->window_type = POTIONS_INVENTORY;
		cell->cell = iEmpty = GetEmptyPotionsInventory(item);
	}
	else if (item->IsBonus())
	{
		cell->window_type = BONUS_INVENTORY;
		cell->cell = iEmpty = GetEmptyBonusInventory(item);
	}
	else if (item->IsChest())
	{
		cell->window_type = CHEST_INVENTORY;
		cell->cell = iEmpty = GetEmptyChestInventory(item);
	}
#endif
	else
	{
		cell->window_type = INVENTORY;
		cell->cell = iEmpty = GetEmptyInventory(item->GetSize());
	}

	return iEmpty != -1;
}

void CHARACTER::SetShopSafebox(offlineshop::CShopSafebox* pk)
{
	if (m_pkShopSafebox && pk == nullptr)
	{
		m_pkShopSafebox->SetOwner(nullptr);
	}

	else if (m_pkShopSafebox == nullptr && pk)
	{
		pk->SetOwner(this);
	}

	m_pkShopSafebox = pk;
}
#endif
// (urmat de:)
//   #ifdef ENABLE_BATTLE_PASS
//   void CHARACTER::GetBattlePass()

